#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2022/10/20 22:40
# @Author  : when
# @File    : zm_proxy.py
# @Description :
import json
import requests

from components.proxy_utils.base_proxy import BaseProxy

try:
    from components.proxy_utils.config import ZM_PROXY_URL
except ImportError:
    ZM_PROXY_URL = "请前往官网获取账户"


class ZMProxy(BaseProxy):
    """
    芝麻代理：https://www.zmhttp.com/
    """

    def __init__(self):
        self.url = ZM_PROXY_URL

    def get_proxy(self):
        res = requests.get(self.url)
        res_data = json.loads(res.text)
        data = res_data.get("data")
        assert len(data), f"获取代理失败, res_data={res_data}"
        data = data[0]
        ip = data.get("ip")
        port = data.get("port")
        return f"{ip}:{port}"


if __name__ == '__main__':
    zm_proxy = ZMProxy()
    print(zm_proxy.get_http_proxy())
